package com.uit.smarttool.ultility;

import java.io.InputStream;
import java.io.OutputStream;

public class Utils {

	// get data from contents of QRCode
	public String[] readString(String input) {
				
				String[] tempPart = input.split(";");
				String[] tempMa = tempPart[0].split(":");
				String[] tempTen = tempPart[1].split(":");
				String[] tempGia = tempPart[2].split(":");

				// 0 1 2 3 4 5
				String[] kq = { tempMa[0], tempMa[1], tempTen[0], tempTen[1],
						tempGia[0], tempGia[1] };

				return kq;
	}
	
	public static void CopyStream(InputStream is, OutputStream os)
    {
        final int buffer_size=1024;
        try
        {
            byte[] bytes=new byte[buffer_size];
            for(;;)
            {
              int count=is.read(bytes, 0, buffer_size);
              if(count==-1)
                  break;
              os.write(bytes, 0, count);
            }
        }
        catch(Exception ex){}
    }
	
	public static String getRandomString(int loai, int dodai) {     
        //Loai : kieu ran dom
        //0 : ngau nhien chi cac chu cai thuong
        //1 : ngau nhien chi cac chu cai hoa
        //2 : ngau nhien ca chu hoa va thuong
        //3 : ngau nhien chu va so
        String ketqua = "";
        String hoa = "QWERTYUIOPASDFGHJKLZXCVBNM";
        String thuong = hoa.toLowerCase();
        String so = "1234567890";
        String randomchuoi = "";
        if (loai < 3 || loai > -1) 
        {
              if (loai == 0) 
              {
            	  randomchuoi = thuong;
              }
        	 else 
        		 if (loai == 1) 
        		 {
        			 randomchuoi = hoa;
        		 }
        		 else
        			 if (loai == 2) 
        			 {
        				 randomchuoi = hoa + thuong;
        			 }
        			 else
        			 {
        				 randomchuoi = hoa + thuong + so;
        			 }
              for (int i = 0; i < dodai; i++)
              {
                  int temp = (int) Math.round(Math.random() * randomchuoi.length());
                  ketqua += randomchuoi.charAt(temp);
              }
        }
        
        return ketqua;
    }	
	
}
